package com.chixing.day04_oop.work;

class Pet{
    public void run(){
        System.out.println("pet is running");
    }
}

class Dog extends Pet{
    public void run(){
        System.out.println("dog is running");
    }
}
//测试类
class Test{
    public static void main(String[] args){
        Pet p1 =  new Dog();
        System.out.println(p1 instanceof Dog);//true
        System.out.println(p1 instanceof Pet);//true
        p1.run();//dog is running

        Dog d1 = (Dog)p1;//true
        System.out.println(d1 instanceof Dog);//true
        System.out.println(d1 instanceof Pet);//true
        d1.run();//dog is running

        Pet p2 =  new Pet();//true
        Dog d2 = (Dog)p2;//false
        System.out.println(d2 instanceof Dog);//不执行
        System.out.println(d2 instanceof Pet);//不执行
    }

}